package controller;

import java.awt.Color;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


import view.AdminPanel;
import view.CenterPanel;
import view.MainFrame;

public class SlideHandler implements ChangeListener{
	
	private MainFrame frame;
	private Color color;
	
	
	/**
	 * Constructor declares an object of the called class MainFrame
	 * @param frame
	 */
	public SlideHandler(MainFrame frame)
	{
		this.frame = frame;	
	}
	/**
	 * Is invoked when the ChangeListener receives an event which 
	 * indicates that a JSliders state has changed
	 */
	public void stateChanged(ChangeEvent event) 
	{
		// Object of JSlider is created, for shortening the code
		JSlider source = frame.getCenterPanel().getAbout().getSlider();
		
		// Color object is set to white
		Color bgColor = Color.WHITE;
		
		// Nested if statements pick up a value, and sets the bgColor to a new state
		if(source.getValue() == 0 && source.getValue() <= 5)
		{
			bgColor = Color.WHITE;
		}
		
		else if(source.getValue() > 5 && source.getValue() <= 10)
		{
			
			bgColor = Color.decode("#81b5e6");
		}
		else if(source.getValue() > 10 && source.getValue() <= 15)
		{
			bgColor = Color.decode("#70818a");
		}
		else if(source.getValue() > 15 && source.getValue() <= 20)
		{
			bgColor = Color.decode("#27533a");
		}
		else if(source.getValue() > 20 && source.getValue() <= 25)
		{
			bgColor = Color.decode("#DE5D83");
		}
		else if(source.getValue() > 25 && source.getValue() <= 30)
		{
			bgColor = Color.decode("#356094");
			
		}
		else if(source.getValue() > 30 && source.getValue() <= 35)
		{
			bgColor = Color.decode("#fffeee");
			
		}
		else if(source.getValue() > 35 && source.getValue() <= 40)
		{
			bgColor = Color.decode("#008abc");
			
		}
		else if(source.getValue() > 40 && source.getValue() <= 45)
		{
			bgColor = Color.decode("#F0DC82");
			
		}
		else if(source.getValue() > 45 && source.getValue() <= 50)
		{
			bgColor = Color.decode("#4bb33d");
			
		}
		else if(source.getValue() > 50 && source.getValue() <= 55)
		{
			bgColor = Color.decode("#93c745");
			
		}
		else if(source.getValue() > 55 && source.getValue() <= 60)
		{
			bgColor = Color.decode("#f63ba1");
			
		}
		else if(source.getValue() > 60 && source.getValue() <= 65)
		{
			bgColor = Color.decode("#4b92bc");
			
		}
		else if(source.getValue() > 65 && source.getValue() <= 70)
		{
			bgColor = Color.decode("#da8b2c");
			
		}
		else if(source.getValue() > 70 && source.getValue() <= 75)
		{
			bgColor = Color.decode("#fffbcb");
			
		}
		else if(source.getValue() > 75 && source.getValue() <= 80)
		{
			bgColor = Color.decode("#fecc99");
			
		}
		else if(source.getValue() > 80 && source.getValue() <= 85)
		{
			bgColor = Color.decode("#1cdd49");
			
		}
		else if(source.getValue() > 85 && source.getValue() <= 90)
		{
			bgColor = Color.decode("#cbfacb");
			
		}
		else if(source.getValue() > 90 && source.getValue() <= 95)
		{
			bgColor = Color.decode("#98feff");
			
		}
		else if(source.getValue() > 95)
		{
			bgColor = Color.decode("#cc98f7");
		}
		
		
		// Object bgColor is passed to method colorChange(Color)
		frame.getColorChanger().colorChange(bgColor);
	}


}
